from CvPythonExtensions import *

import PlanetfallSpells
from PlanetfallSpells import PlanetfallSpellImmediateBase

gc = CyGlobalContext()

class Haste(PlanetfallSpellImmediateBase):
    def __init__(self):
        PlanetfallSpellImmediateBase.__init__(self)

        self.pCastingUnits = []
        # Fill list with units that can cast, such as..
        #self.pCastingUnits.append( gc.getInfoTypeForString("UNIT_NAME_1") )
        #self.pCastingUnits.append( gc.getInfoTypeForString("UNIT_NAME_2") )

    def canUnitCast(self, pCastingUnit, pPlot, bVisible):
        if not pCastingUnit.getUnitType() in self.pCastingUnits:
            return False

        if (pCastingUnit.baseCombatStr() > 0):
            iMinHitPoints = (pCastingUnit.maxHitPoints() / 3) + 1 # Roundoff
            if (pCastingUnit.currHitPoints() > iMinHitPoints):
                return True

        return False

    def startSpellResults(self, pCastingGroup, pTarget):
        for pUnit in pCastingGroup.getUnits():
            if self.canUnitCast(pUnit, pUnit.plot(), True):
                iChangeHitPoints = (pUnit.maxHitPoints() / 3) + 1 # Roundoff
                pUnit.changeDamage(iChangeHitPoints, pUnit.getOwner())
                pUnit.setMoves(0)
